package controllers.vecino;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import services.PagoService;
import controllers.AbstractController;
import domain.Pago;

@Controller
@RequestMapping("/pago/vecino")
public class PagoVecinoController extends AbstractController {

	@Autowired
	private PagoService pagoService;

	public PagoVecinoController() {
		super();
	}

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public ModelAndView list(@RequestParam int comunidadId) {
		ModelAndView result;
		Collection<Pago> pagos;

		pagos = pagoService.findPagosByComunidadDeVecinosAndVecino(comunidadId);

		result = new ModelAndView("pago/list");
		result.addObject("requestURI", "pago/vecino/list.do");
		result.addObject("pagos", pagos);
		result.addObject("backURI", "/comunidad/vecino/edit.do?comunidadId="
				+ comunidadId);

		return result;
	}

}
